New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feature request] More intelligent compression #116
Comments
I think this should be part of new option to enable / disable optimizations. Another opportunity for optimizations is coalescing common properties: /* for example: */
.foo { width: 10px; height: 10px; color: red; }
.bar { width: 10px; height: 10px; color: yellow; }
/* would become: */
.foo, .bar { width:10px; height:10px; }
.foo { color: red; }
.bar { color: yellow } This kind of optimization is not safe however and therefore users should be able to test and see what side effects if any appear. |
+1 |
This may not be 100% related to this thread but I've seen every other marginally related ticket being closed and referred here. Specifically for dealing with media queries it would be useful to use some sort of output buffering to stash some css rules for later inclusion. The issue is hinted at in the media queries blog article where trying to correct for media queries inline will result in a number of identical Buffering is a completely different usecase than a Here's a simple example: .left-column {
width: 300px; // for browsers that don't support media queries
@buffer small-devices {
& { width: 100%; }
}
@buffer medium-devices {
& { width: 150px; }
}
@buffer large-devices {
& { width: 300px; }
}
}
.main-column {
width: 660px; // for browsers that don't support media queries
@buffer small-devices {
& { width: 100%; }
}
@buffer medium-devices {
& { width: 330px; }
}
@buffer large-devices {
& { width: 660px; }
}
}
@media only screen and (min-width: 0) {
@output small-devices;
}
@media only screen and (min-width: 768px) {
@output medium-devices;
}
@media only screen and (min-width: 992px) {
@output large-devices;
}
|
Didn't think about an output buffer approach for media queries but I gotta say it doesn't look bad. |
+1 |
The buffer solution really looks good here... |
+1 |
yeah +1 for the buffer ! |
+1 |
|
+1 for everything suggested! |
+1 for sure. |
+1 Great solution. Buffer would be a great feature. |
+1 for not repeating "@media screen and" a thousand times in my live file |
I've been hacking on a I plan on using this for my own projects, but if there is enough interest and the code is bug-free, I would be happy to submit a pull request for inclusion in core Sass. The syntax I used is: $device-size: small;
$device-width: 640px;
body {
color: white;
@buffer #{$device-size}-screen {
color: black;
}
}
h1 {
color: white;
@buffer #{$device-size}-screen {
color: black;
.no-js & { color: red; }
}
}
@media only screen and (max-width: #{$device-width}) {
@flush #{$device-size}-screen;
} Several features can be seen in action in the snippet above:
There is support for using $device-size: small
$device-width: 640px
body
color: white
#{$device-size}-screen ->
color: black
h1
color: white
#{$device-size}-screen ->
color: black
.no-js &
color: red
@media only screen and (max-width: #{$device-width})
<- #{$device-size}-screen What doesn't work / is missing
Try it out
Feedback welcomed very much. |
@StanAngeloff Very interested by this, it would be great if this was implemented into Sass. |
+1 |
Does anyone have any reasoning for why this wouldn't be possible? |
+1. Media queries are fundamentals these days, so would be really handy a more efficient way to manage the output to group them. Could be the one suggested by @heygrady —great idea BTW—, or another one, but would be nice to see some changes in the current approach. |
+1 |
@StanAngeloff Please open a separate pull request for your |
@nex3 I think that @heygrady should open the separated pull request, since was his original idea and he probably can explain more in deep the matter. It's a really good idea the |
+1. Would love to see something like this. |
@imbatta I didn't write any code, I was just offering an idea. I couldn't create a pull request without code. But thanks for thinking of me. |
@heygrady Oh, you're right, I kinda suck in some GitHub stuff yet; sorry for the misunderstood. Hope the But coming back to the original feature request, I don't think it's a good idea. These kind of compilation will cause many headaches for sure. Anyway, if many people is interested, it could be an optional way to compile. |
+1 |
1 similar comment
+1 |
I like @lunelson's idea of applying It should group mixin @mixin breakpoint($width) {
@media (min-width: $width) {
@content;
}
}
@buffer breakpoint(700px) {
h1 {
color: red;
}
}
@buffer breakpoint(700px) {
p {
color: blue;
}
}
@buffer breakpoint(900px) {
p {
color: purple;
}
}
@flush breakpoint; Should output: @media (min-width: 700px) {
h1 {
color: red;
}
p {
color: blue;
}
}
@media (min-width: 900px) {
p {
color: purple;
}
} |
+1 for
(LESS has additive mixin declarations, which can be a real pain, but also proves incredibly powerful at times.) |
+1 |
+1 to use the css-condense logic. |
👍 |
Late to the party, but to me, an extension to Sass based on @stoyan's CSSShrink would be fantastic for intelligent compression. I do understand the challenges there though. Not trivial at all. http://cssshrink.com/velocity/ |
+1 for buffer |
For anyone who is using gulp, just use https://www.npmjs.com/package/gulp-combine-media-queries It will combine your media queries together for you after compilation is complete. Works perfectly. |
+1 for buffer |
+1 for buffer. Being able to nest related CSS and then control where it gets output seems like a generally useful tool. Something like: @buffer("label") {
// SCSS code
}
@flush("label"); Then... // Mobile First BABY!!
.box {
margin: 20px 10px;
@buffer("tablet") {
margin-left: 20px;
margin-right: 20px;
}
@buffer("desktop") {
margin-top: 40px;
margin-bottom: 40px;
}
}
// elsewhere
@media (min-width: 600px) {
@flush("tablet"); // Outputs .box overrides and anything else in "tablet" buffer
}
@media (min-width: 900px) {
@flush("desktop"); // Outputs .box overrides and anything else in "desktop" buffer
} |
+1 for buffer |
Hi! I saw this discussion is really old, but I think there's something new to be considered: HTTP/2. Soon, the good practice concerning requests will be "it depends". On HTTP/2 is better to split the CSS by media query and to reduce the file size. So, maybe it's better to keep every Thanks! |
+1 |
+1 |
hi, |
+1 |
1 similar comment
+1 |
Please use emoji, instead of +1. Use comments for something really helpful for the issue. |
Ok, sorry for that. El 7/6/16 a las 12:10, Dmitry Polushkin escribió:
David Saenz / david@herokidstudio.es mailto:david@herokidstudio.es / _Herokid Studio_™ |
These optimizations are no longer planned. Sass does what it can to eliminate extra whitespace and choose the smallest possible representation for values, but it's primary focus is being the best preprocessing language it can be rather than the best CSS compressor. Other tools exist that are focused on maximal optimization, and those are a better place for features like this. In addition:
|
It would be great if SASS output could be configured to more intelligently compress output. Here are some examples:
This would allow you to more expressively organise stylesheets and partials without sacrificing on output length. For example, you could have color, typography and layout partials which, when compiled, gave the same output as if they had been written all mixed together.
There maybe gotchas with doing this due to the cascading nature of stylesheets and this effectively changes the ordering of declarations. However, I can't immediately think of specifics and the first case at least does not seem to be problematic.
This should also only apply when the compressed output option has been set as the readability of stylesheets may be impacted. For example, in development, it might be useful for the output to indicate that the designer has intended to split declarations in a particular way.
The text was updated successfully, but these errors were encountered: